from flask import g
# from cache.user import UserStatusCache


# 判断用户登陆
def loginrequired(func):
    def wrapper(*args, **kwargs):
        # 暂时没讲如何获取user_id
        user_id = g.user_id
        # user_id = None
        # 判断user_id的
        if user_id is None:
            return {'message': 'please login'}, 401

        # 判断下refresh_token
        elif g.is_refresh_token:
            return {'message': 'do not use refresh token'}, 403

        else:
            return func(*args, **kwargs)

    return wrapper
